// class Person {
//     age = 12
// }
// const p1 = new Person()

import dayjs from 'dayjs';

// console.log(`p1 constructor is`, p1.constructor);

// const book = {}
// Object.defineProperties(book, {
//     year_: {
//         value: 2023,
//         writable:true
//     },
//     edition: {
//         value: 1,
//         writable:true
//     },
//     year: {
//         get() {
//             return this.year_
//         },
//         set(newYear) {
//             if (newYear > 2023) {
//                 this.year_ = newYear
//                 this.edition += newYear - 2023
//             }
//         }
//     }
// })

// book.year = 2025

// console.log(Object.getOwnPropertyDescriptors(book));

// const a = {
//     name: 'a',
//     age_: 12,
//     get age() { return this.age_ },
//     set age(newAge) {
//         this.age_ = newAge
//     }
// }
// const b = {
//     // set age(newAge: number | string) { console.log('set b age', newAge) }
//     get age() { return 'ddd' }
// }

// // console.log(`a is`, Object.getOwnPropertyDescriptor(a, 'name'));
// console.log(Object.assign({}, a, b));

interface person {
  name: string;
  age: number;
  job?: string;
}

class Person {
  static f1 = 1;
  static f2 = 2;
  #birthday = dayjs().format('YYYY-MM-DD');
  job = '';

  constructor(
    public name: string,
    birthday?: string,
  ) {
    if (birthday) this.birthday = birthday;
  }
  /**
   * 生日
   */
  get birthday() {
    return this.#birthday;
  }
  set birthday(birthday) {
    if (dayjs(birthday, 'YYYY-MM-DD').isValid()) this.#birthday = birthday;
    throw new Error('格式错误，应该是YYYY-MM-DD');
  }

  /**
   * 年龄
   *
   * @readonly
   * @type {*}
   */
  get age() {
    return dayjs().diff(dayjs(this.birthday, 'YYYY-MM-DD'), 'years');
  }

  static getPrp() {
    console.log(Person.f1, Person.f2, Person.name, Person);
  }
}

class Student extends Person {
  static f1 = 23;
  grade?: string;
  constructor(name: string, birthday?: string) {
    super(name, birthday);
  }

  getStatic() {
    console.log(super.age);
  }

  static getStatic() {
    console.log(Person.f1);
  }
}

const p1: person = new Person('zzb');

const s1 = new Student('baz');

// console.log(`test prototype`,Object.getPrototypeOf(p1) === Person.prototype);
// console.log(Object.entries(p1));
console.log(p1, Person);
console.log(s1);
Student.getPrp();
Student.getStatic();

// console.log(`p1 is`, Object.hasOwn(Object.getPrototypeOf(p1), 'constructor'), p1.constructor);
